package com.haowu.product.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.haowu.common.core.domain.R;
import com.haowu.common.core.validate.AddGroup;
import com.haowu.common.core.validate.EditGroup;
import com.haowu.common.core.web.controller.BaseController;
import com.haowu.common.excel.utils.ExcelUtil;
import com.haowu.common.log.annotation.Log;
import com.haowu.common.log.enums.BusinessType;
import com.haowu.common.mybatis.core.page.PageQuery;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.haowu.product.domain.vo.HwServiceVo;
import com.haowu.product.domain.bo.HwServiceBo;
import com.haowu.product.service.IHwAppServiceService;
import com.haowu.common.mybatis.core.page.TableDataInfo;

import java.util.List;
import java.util.Arrays;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.servlet.http.HttpServletResponse;

/**
 * 好务服务项目控制器
 * 前端访问路由地址为:/product/hwAppService
 *
 * @author lky
 * @date 2023-02-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/hwAppService")
public class HwAppServiceController extends BaseController {

    private final IHwAppServiceService iHwAppServiceService;

    /**
     * 查询好务服务项目列表
     */
    @SaCheckPermission("product:hwAppService:list")
    @GetMapping("/list")
    public TableDataInfo<HwServiceVo> list(HwServiceBo bo, PageQuery pageQuery) {
        return iHwAppServiceService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出好务服务项目列表
     */
    @SaCheckPermission("product:hwAppService:export")
    @Log(title = "好务服务项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HwServiceBo bo, HttpServletResponse response) {
        List<HwServiceVo> list = iHwAppServiceService.queryList(bo);
        ExcelUtil.exportExcel(list, "好务服务项目", HwServiceVo.class, response);
    }

    /**
     * 获取好务服务项目详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("product:hwAppService:query")
    @GetMapping("/{id}")
    public R<HwServiceVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(iHwAppServiceService.queryById(id));
    }

    /**
     * 新增好务服务项目
     */
    @SaCheckPermission("product:hwAppService:add")
    @Log(title = "好务服务项目", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HwServiceBo bo) {
        return toAjax(iHwAppServiceService.insertByBo(bo));
    }

    /**
     * 修改好务服务项目
     */
    @SaCheckPermission("product:hwAppService:edit")
    @Log(title = "好务服务项目", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HwServiceBo bo) {
        return toAjax(iHwAppServiceService.updateByBo(bo));
    }

    /**
     * 删除好务服务项目
     *
     * @param ids 主键串
     */
    @SaCheckPermission("product:hwAppService:remove")
    @Log(title = "好务服务项目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        return toAjax(iHwAppServiceService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
